package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.mapper.ChatRecordMapper;
import com.ruoyi.system.domain.ChatRecord;
import com.ruoyi.system.service.IChatRecordService;

/**
 * 记录Service业务层处理
 *
 * @author trip
 * @date 2024-09-20
 */
@Service
public class ChatRecordServiceImpl extends ServiceImpl<ChatRecordMapper, ChatRecord> implements IChatRecordService {

    @Autowired
    private ChatRecordMapper chatRecordMapper;

    /**
     * 查询记录
     *
     * @param recordId 记录主键
     * @return 记录
     */
    @Override
    public ChatRecord selectChatRecordByRecordId(Long recordId) {
        return chatRecordMapper.selectChatRecordByRecordId(recordId);
    }

    /**
     * 查询记录列表
     *
     * @param chatRecord 记录
     * @return 记录
     */
    @Override
    public List<ChatRecord> selectChatRecordList(ChatRecord chatRecord) {
        return chatRecordMapper.selectChatRecordList(chatRecord);
    }

    /**
     * 新增记录
     *
     * @param chatRecord 记录
     * @return 结果
     */
    @Override
    public int insertChatRecord(ChatRecord chatRecord) {
                chatRecord.setCreateTime(DateUtils.getNowDate());
            return chatRecordMapper.insertChatRecord(chatRecord);
    }

    /**
     * 修改记录
     *
     * @param chatRecord 记录
     * @return 结果
     */
    @Override
    public int updateChatRecord(ChatRecord chatRecord) {
                chatRecord.setUpdateTime(DateUtils.getNowDate());
        return chatRecordMapper.updateChatRecord(chatRecord);
    }

    /**
     * 批量删除记录
     *
     * @param recordIds 需要删除的记录主键
     * @return 结果
     */
    @Override
    public int deleteChatRecordByRecordIds(Long[] recordIds) {
        
            LambdaUpdateWrapper<ChatRecord> wrapper;
            for (Long id : recordIds) {
                wrapper = Wrappers.lambdaUpdate(ChatRecord.class)
                .eq(ChatRecord::getRecordId, id)
                    .set(ChatRecord::getDelFlag, "1");
                super.update(new ChatRecord(), wrapper);
            }
            return 1;
    }

    /**
     * 删除记录信息
     *
     * @param recordId 记录主键
     * @return 结果
     */
    @Override
    public int deleteChatRecordByRecordId(Long recordId) {
        return chatRecordMapper.deleteChatRecordByRecordId(recordId);
    }
}



